package com.jwsoft.manager.common.vo.eduAddressTree;

import com.jwsoft.manager.common.enums.DataSaveEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.*;

/**
 * 地址树VO，用于前端展示
 *
 * @author fangs
 */
@Data
@Schema(name = "AddressTreeVO", title = "地址树VO", description = "地址树VO")
public class AddressTreeVO implements Serializable {

    private static final Long serialVersionUID = 1L;

    private static final String EDU_ADDRESS_ID_SEPARATOR = ",";

    @Schema(name = "addressId", title = "地址id")
    private Long addressId;

    @Schema(name = "areaCode", title = "行政区划编码")
    private String areaCode;

    @Schema(name = "areaName", title = "组织名称")
    private String areaName;

    @Schema(name = "areaType", title = "行政区划类型 ")
    private String areaType;

    @Schema(name = "areaTypeName", title = "行政区划类型 ")
    private String areaTypeName;

    @Schema(name = "contact", title = "联系人")
    private String contact;

    @Schema(name = "cellphone", title = "联系人手机")
    private String cellphone;

    @Schema(name = "phone", title = "联系人电话")
    private String phone;

    @Schema(name = "rate", title = "级别")
    private Integer rate;

    @Schema(name = "orderNo", title = "排序号")
    private Integer orderNo;

    @Schema(name = "primarySchool", title = "小学默认学校组织id")
    private String primarySchool;

    @Schema(name = "middleSchool", title = "中学默认学校组织id")
    private String middleSchool;

    @Schema(name = "checkPrimaryList", title = "小学默认学校组织id列表")
    private List<String> checkPrimaryList;

    @Schema(name = "middleSchool", title = "中学默认学校组织id列表")
    private List<String> checkMiddleList;

    @Schema(name = "parentId", title = "上级地址/区域")
    private Long parentId;

    @Schema(name = "searchTerm", title = "检索项，使用#分割")
    private String searchTerm;

    @Schema(name = "isLeafNode", title = "是否叶子节点")
    private Integer leafNode;

    @Schema(name = "fullAddress", title = "完整地址信息")
    private String fullAddress;

    @Schema(name = "majorPointer", title = "映射记录指针，对应映射记录主键address_id")
    private Long majorPointer;

    @Schema(name = "eduAddressId", title = "edu_address主键")
    private String eduAddressId;

    @Schema(name = "isLastNode", title = "是否最后非叶子节点-es数据检索节点")
    private Integer lastNode;

    /**
     * 原始地址
     */
    @Schema(name = "originAdd", title = "原始地址")
    private String originAdd;

    @Schema(name = "childNode", title = "子集节点")
    private List<AddressTreeVO> childNode;

    @Schema(name = "isRelation", title = "和学校有关联")
    private Boolean relation;

    @Schema(name = "matchNode", title = "是否是匹配节点")
    private Boolean matchNode;

    @Schema(name = "changeNode", title = "是否变更")
    private Integer changeNode;

    /**
     * 当前数据是否保存到数据库(合并节点的保存标记)
     */
    @Schema(name = "saveFlag", title = "保存标记")
    private Boolean saveFlag;

    @Schema(name = "saveData", title = "需要保存的数据")
    private Map<DataSaveEnum, List<EduAddressTreeVO>> saveData;

    @Schema(name = "leafNum", title = "叶子节点数")
    private Integer leafNum;

    @Schema(name = "esStatus", title = "0:未存到es,1:已保存到es")
    private Integer esStatus;

    @Schema(name = "esMsg", title = "es状态描述")
    private String esMsg;

    @Schema(name = "esTime", title = "保存es时间")
    private Date esTime;

    @Schema(name = "affirm_flag", title = "地址节点是否确认标志：0 未确认，1 确认")
    private Integer affirmFlag;

    public List<String> getEduAddressIdList() {
        if (StringUtils.isBlank(eduAddressId)) {
            return new ArrayList<>(0);
        }
        return new ArrayList<>(Arrays.asList(eduAddressId.split(EDU_ADDRESS_ID_SEPARATOR)));
    }
}
